﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Configuration;
using CE.Global;
using CE.User;
using CE.Image;
using CE.CarInsurance;
using CE.Mail;
using CE.Company;
using CE.Database;
using CE.Promotion;
using CE.Security;

public partial class motor_fleet_insurance_motor_fleet_insurance_th : MyLanguageBasePage
{
    CE.User.Profile _profile = null;
    CE.User.ProfileDB _profiledb = null;
    Contact _contact = null;
    ContactDB _contactdb = null;
    string _redirectUrl = "";
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.Page.Title = Resources.Title.MotorFleetTitle;

        LiteralControl newln = new LiteralControl(Environment.NewLine);
        HtmlMeta language = new HtmlMeta();
        language.Name = "language";
        language.Content = Resources.Title.PageLanguage;

        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = Resources.Title.MotorFleetKeyword;

        HtmlMeta description = new HtmlMeta();
        description.Name = "description";
        description.Content = Resources.Title.MotorFleetDescription;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);
        Page.Header.Controls.AddAt(12, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(13, keywords);
        Page.Header.Controls.AddAt(14, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(15, description);
        if (!IsPostBack)
        {
            txtCompanyName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCompanyName.ClientID + "','" + rfvCompanyName.ClientID + "','" + revCompanyName.ClientID + "');");
            txtName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtName.ClientID + "','" + rfvName.ClientID + "','" + revName.ClientID + "');");
            txtEmail.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail.ClientID + "','" + rfvEmail.ClientID + "','" + revEmail.ClientID + "');");
            txtMobile.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMobile.ClientID + "','" + rfvMobile.ClientID + "','" + revMobile.ClientID + "');");
            txtCompanyContactNo.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCompanyContactNo.ClientID + "','" + rfvCompanyContactNo.ClientID + "','" + revCompanyContactNo.ClientID + "');");
            txtNoOfCars.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtNoOfCars.ClientID + "','" + rfvNoOfCars.ClientID + "','" + revNoOfCars.ClientID + "');");
            ddlCallMeTime.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCallMeTime.ClientID + "','" + rfvCallMeTime.ClientID + "');");

            Page.Form.DefaultButton = btnSubmit.UniqueID;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            ChangeValidationEffectServerSide("fleetrequest");
            Page.Validate("fleetrequest");
            if (Page.IsValid)
            {
                if (txtMobile.Text.Trim().Length == 10)
                {
                    int _isexistuser = 0;
                    Int64 _AgentId = 0;
                    Int64 _result = -1;
                    string _ComapanyName = txtCompanyName.Text.Trim();
                    string _Name = txtName.Text.Trim();
                    string _Email = txtEmail.Text.Trim().ToLower();
                    string _Mobile = txtMobile.Text.Trim();
                    string _CompanyContactNo = txtCompanyContactNo.Text.Trim();
                    if (txtExtension.Text.Trim().Length > 0)
                    {
                        _CompanyContactNo = _CompanyContactNo + " exten. " + HttpUtility.HtmlEncode(txtExtension.Text).Trim();
                    }
                    FleetRequest _fleetrequest = new FleetRequest();
                    FleetRequestDB _fleetrequestdb = new FleetRequestDB();
                    _fleetrequest.RequestId = 0;
                    _fleetrequest.CompanyName = _ComapanyName;
                    _fleetrequest.Name = _Name;
                    _fleetrequest.Email = _Email;
                    _fleetrequest.Mobile = _Mobile;
                    _fleetrequest.CompanyContactNo = _CompanyContactNo;
                    _fleetrequest.NoOfCars = Convert.ToInt32(txtNoOfCars.Text);
                    _fleetrequest.CallAt = Convert.ToInt16(ddlCallMeTime.SelectedValue);
                    _fleetrequest.AgentId = _AgentId;
                    _fleetrequest.IsExistCustomer = _isexistuser;
                    _fleetrequest.IsAcceptTC = Convert.ToInt16(txtIsAccept.Text);
                    _result = _fleetrequestdb.Insert(_fleetrequest);
                    _fleetrequest = null;
                    _fleetrequestdb = null;
                    if (_result != -1)
                    {

                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "alertThxU", "alert('" + Resources.CarInsurance.CallMeMessage + "')", true);

                        #region Hide Call me email sending - Sakthi on 11 Dec 2014
                        string _message = "";
                        string _title = "";

                        txtName.Text = General.ClearScriptTag(txtName.Text);
                        _title = "GG Car Fleet Enquiry by " + Server.HtmlEncode(txtName.Text);

                        _message = "Company Name: " + _ComapanyName;
                        _message += "<br/><br/>Name : " + _Name;
                        _message += "<br/><br/>Email : " + _Email;
                        _message += "<br/><br/>Mobile No : " + _Mobile;
                        _message += "<br/><br/>Company Contact No : " + _CompanyContactNo;
                        _message += "<br/><br/>No. of Cars : " + txtNoOfCars.Text.Trim();
                        _message += "<br/><br/>Call Time : " + ddlCallMeTime.SelectedItem.Text;
                        string _emailList = ConfigurationManager.AppSettings["TH.FleetEnquiryReceiver"].ToString();
                        MyMailManager.SendFleetEnquiry(_emailList, _title, _message);
                        #endregion

                        _redirectUrl = CE.Global.General.GetUrl("/user/user-message", Page);
                        Session["UMMSG"] = "UMG,1994";
                        Response.Redirect(_redirectUrl);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, this.GetType(), "alertThxU", "alert('Saving did NOT succees!');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        txtCompanyName.Text = HttpUtility.HtmlEncode(txtCompanyName.Text);
        txtName.Text = HttpUtility.HtmlEncode(txtName.Text);
        txtEmail.Text = HttpUtility.HtmlEncode(txtEmail.Text);
        txtMobile.Text = HttpUtility.HtmlEncode(txtMobile.Text);
        txtCompanyContactNo.Text = HttpUtility.HtmlEncode(txtCompanyContactNo.Text);
        txtNoOfCars.Text = HttpUtility.HtmlEncode(txtNoOfCars.Text);

        #region Customer

        //CompanyName
        if (rfvCompanyName.Enabled && rfvCompanyName.ValidationGroup == strValidationGroup)
        {
            rfvCompanyName.Validate();
            if (rfvCompanyName.IsValid == false)
            {
                txtCompanyName.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtCompanyName.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtCompanyName.ControlStyle.CssClass = "input-fields";
        }

        if (revCompanyName.Enabled && revCompanyName.ValidationGroup == strValidationGroup)
        {
            if (rfvCompanyName.IsValid)
            {
                revCompanyName.Validate();
                if (revCompanyName.IsValid == false)
                {
                    txtCompanyName.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtCompanyName.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtCompanyName.ControlStyle.CssClass = "input-fields";
        }

        //Name
        if (rfvName.Enabled && rfvName.ValidationGroup == strValidationGroup)
        {
            rfvName.Validate();
            if (rfvName.IsValid == false)
            {
                txtName.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtName.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "input-fields";
        }

        if (revName.Enabled && revName.ValidationGroup == strValidationGroup)
        {
            if (rfvName.IsValid)
            {
                revName.Validate();
                if (revName.IsValid == false)
                {
                    txtName.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtName.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtName.ControlStyle.CssClass = "input-fields";
        }

        //Email
        if (rfvEmail.Enabled && rfvEmail.ValidationGroup == strValidationGroup)
        {
            rfvEmail.Validate();
            if (rfvEmail.IsValid == false)
            {
                txtEmail.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtEmail.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "input-fields";
        }

        if (revEmail.Enabled && revEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail.IsValid)
            {
                revEmail.Validate();
                if (revEmail.IsValid == false)
                {
                    txtEmail.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtEmail.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtEmail.ControlStyle.CssClass = "input-fields";
        }

        //MobileNo
        if (rfvMobile.Enabled && rfvMobile.ValidationGroup == strValidationGroup)
        {
            rfvMobile.Validate();
            if (rfvMobile.IsValid == false)
            {
                txtMobile.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtMobile.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtMobile.ControlStyle.CssClass = "input-fields";
        }

        if (revMobile.Enabled && revMobile.ValidationGroup == strValidationGroup)
        {
            if (rfvMobile.IsValid)
            {
                revMobile.Validate();
                if (revMobile.IsValid == false)
                {
                    txtMobile.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtMobile.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtMobile.ControlStyle.CssClass = "input-fields";
        }

        //CompanyContactNo
        if (rfvCompanyContactNo.Enabled && rfvCompanyContactNo.ValidationGroup == strValidationGroup)
        {
            rfvCompanyContactNo.Validate();
            if (rfvCompanyContactNo.IsValid == false)
            {
                txtCompanyContactNo.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtCompanyContactNo.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtCompanyContactNo.ControlStyle.CssClass = "input-fields";
        }

        if (revCompanyContactNo.Enabled && revCompanyContactNo.ValidationGroup == strValidationGroup)
        {
            if (rfvCompanyContactNo.IsValid)
            {
                revCompanyContactNo.Validate();
                if (revCompanyContactNo.IsValid == false)
                {
                    txtCompanyContactNo.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtCompanyContactNo.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtCompanyContactNo.ControlStyle.CssClass = "input-fields";
        }

        //NoOfCars
        if (rfvNoOfCars.Enabled && rfvNoOfCars.ValidationGroup == strValidationGroup)
        {
            rfvNoOfCars.Validate();
            if (rfvNoOfCars.IsValid == false)
            {
                txtNoOfCars.ControlStyle.CssClass = "input-fields validationError";
            }
            else
            {
                txtNoOfCars.ControlStyle.CssClass = "input-fields";
            }
        }
        else
        {
            txtNoOfCars.ControlStyle.CssClass = "input-fields";
        }

        if (revNoOfCars.Enabled && revNoOfCars.ValidationGroup == strValidationGroup)
        {
            if (rfvNoOfCars.IsValid)
            {
                revNoOfCars.Validate();
                if (revNoOfCars.IsValid == false)
                {
                    txtNoOfCars.ControlStyle.CssClass = "input-fields validationError";
                }
                else
                {
                    txtNoOfCars.ControlStyle.CssClass = "input-fields";
                }
            }
        }
        else
        {
            txtNoOfCars.ControlStyle.CssClass = "input-fields";
        }

        //CallMeTime
        if (rfvCallMeTime.Enabled && rfvCallMeTime.ValidationGroup == strValidationGroup)
        {
            rfvCallMeTime.Validate();
            if (rfvCallMeTime.IsValid == false)
            {
                ddlCallMeTime.ControlStyle.CssClass = "input-fields-dropdown validationError";
            }
            else
            {
                ddlCallMeTime.ControlStyle.CssClass = "input-fields-dropdown";
            }
        }
        else
        {
            ddlCallMeTime.ControlStyle.CssClass = "input-fields-dropdown";
        }

        #endregion
    }

}
